﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DataGridTest.Converters;
using DataGridTest.Models;

namespace DataGridTest
{
    public partial class MainPage : UserControl
    {
        ObservableCollection<ProvinceModel> _provinces = new ObservableCollection<ProvinceModel>();

        public MainPage()
        {
            InitializeComponent();

            InitControl();

            XGrid.DataContext = _provinces;
            XFlexGrid.DataContext = _provinces;
        }

        private void InitControl()
        {
            for (int i = 1; i <= 20; i++)
            {
                ProvinceModel model = new ProvinceModel()
                {
                    Number = i,
                    Classes = "等级" + i,
                    Province = "省份" + i,
                    Legal = "合法" + i,
                    Illegal = "非法" + i,
                    Unknown = "未知" + i
                };
                _provinces.Add(model);
            }

            PagedCollectionView view = new PagedCollectionView(_provinces);
            using (view.DeferRefresh())
            {
                view.GroupDescriptions.Clear();
                view.GroupDescriptions.Add(new PropertyGroupDescription("Classes"));
            }
            XFlexGrid.GroupHeaderConverter = new GroupHeaderConverter();
            XFlexGrid.ItemsSource = view;
            XFlexGrid.CollapseGroupsToLevel(0);
        }

    }
}
